<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isAll" />
    <label for="toggle-all"></label>
    <input
      v-model.trim.lazy="name"
      @keyup.enter="down"
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
    />
  </header>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      default: ()=>[]
    },
  },
  data() {
    return {
      name: "",
    };
  },
  methods: {
    down() {
      if (!this.name.length) {
        return alert("待办事件不能给你为空！");
      }
      this.$emit("add", this.name), (this.name = "");
    },
  },
  computed: {
    isAll:{
      get(){
       return this.list.every(item=>item.isDone === true)
      },
      set(isChecked){
        this.$emit('allo',isChecked)
      }
    }
  }
};
</script>